<template>
  <div class="content">
    <div class="top">
      <div @click="isShow(0)" :class="curId===0?'select':''">商品管理 <i :class="{num:true,select:curId === 0?true:false}">{{number1}}</i>
      </div>
      <div @click="isShow(1)" :class="curId===1?'select':''">拼单管理 <i
        :class="{num:true,select:curId === 1? true : false}">{{number2}}</i></div>
    </div>
    <div class="con">

      <ul v-show="curId===0" class="goodsList">
        <!--<mt-loadmore :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" :auto-fill="false" ref="loadmore">-->
          <li class="item" v-for="(item , index) in goodsList">
            <div class="goods">
              <div class="img">
                <img :src=item.detailsImg alt="">
              </div>
              <div class="text">
                <p>{{item.mallName}}</p>
                <p><span class="sale">&yen{{item.salePrice/100}}</span> <span
                  class="kuncun">库存：{{item.mallCount}}</span></p>
                <p><span>佣金:  &yen{{item.salePrice/100 * item.commissionRatio/100}}</span><span>佣金比例:  {{item.commissionRatio}}%</span>
                </p>
              </div>
            </div>
            <div class="bottom">
              <div class="down" v-show="false" @click="removeItem(index)">下架</div>
              <div class="gopin" @click="goPinDan(index)">发起拼单</div>
            </div>
          </li>
        <!--</mt-loadmore>-->
      </ul>

      <ul v-show="curId===1" class="pinDanList">

        <li class="item" v-for="(item , index) in pindanList">
          <div class="goods">
            <div class="img">
              <img :src=item.detailsImg alt="">
            </div>
            <div class="text">
              <p>{{item.mallName}}</p>
              <p>&yen{{item.salePrice/100}}</p>
              <p><span>佣金:  &yen{{item.salePrice/100 * item.commissionRatio/100}}</span><span>佣金比例:  {{item.commissionRatio}}%</span>
              </p>
            </div>
          </div>
          <div class="bottom">
            <div class="down" @click="removeItem(index)">下架</div>
            <div class="gopin" @click="goPinDan(index)">发起拼单</div>
          </div>
        </li>

      </ul>

    </div>
    <footer>
      <div @click="removeAll">全部删除</div>
      <div>全部下架</div>
    </footer>
  </div>
</template>

<script>
  import wx from 'weixin-js-sdk'
  import {
    wxHttpTool,
    wx_config,
    http_getParam,
    get_shopQrcoe,
    wx_share,
    wx_hideAllMenu
  } from '../../components/httpUtil/httpUtil'
  import {msg_10046} from '../../message/msg_10046'
  export default {
    name: "Management",
    data() {
      return {
        goodsList: [],
        pindanList: [],
        startIndex: 0,
        allLoaded: false,
        curId: 0,
        isAll: true,
        num1: 0,
        num2: 0,
        inventory: ''
      }
    },
    created() {
      wxHttpTool.wxAuthor(this, function (varRet, varJson, varThis = this) {
        if (varRet == -1) {
          varThis.alertTip('网络错误');
          varThis.go = function () {
            varThis.showAlert = false;
          }

          // 关注钱应该判断下是否已经关注过了
          msg_10046.send(varThis,msg_10046.entity(),function(varThis,res){
            varThis.wxlist=res.data.p.sign
            wx_config(varThis.wxlist);
            wx_hideAllMenu();
            wx.hideMenuItems({
              //禁用单独分享朋友圈QQ空间等功能
              menuList: ["menuItem:share:timeline","menuItem:share:QZone","menuItem:share:qq"] // 要隐藏的菜单项，所有menu项见附录3
            });
          })

        }
        // 关注钱应该判断下是否已经关注过了
        msg_10046.send(varThis, msg_10046.entity(), function (varThis, res) {
          varThis.wxlist = res.data.p.sign
          wx_config(varThis.wxlist);
          wx_hideAllMenu();
          wx.hideMenuItems({
            //禁用单独分享朋友圈QQ空间等功能
            menuList: ["menuItem:share:timeline", "menuItem:share:QZone", "menuItem:share:qq"] // 要隐藏的菜单项，所有menu项见附录3
          });
        })


      }, this.type)
      this.fn10040();
      this.fn10041();
    },
    methods: {
      // 商品管理
      fn10040(startIndex) {
        let jsonValue = JSON.stringify(
          {
            'c': '10040',
            'p': {
              'tokenId': token(),
              'userId': JSON.parse(window.localStorage.data).id,
              "startIndex": startIndex ? startIndex : 0, // 开始位置
              "pageSize": 10,   // 分页总数量
            }
          }
        )
        this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
          console.log(res)
          const data = res.data.p;
          if (data.isTrue) {
            this.goodsList = [...this.goodsList, ...res.data.p.purchaseMallList]
          } else {
            this.alertTip(data.errorMsg);
            if (data.errorCode === 90) {
              this.go = () => {
                this.showAlert = false
                let _this = this
                relogin(_this)
              }
            }
          }

        })
      },
      //拼单管理
      fn10041() {
        let jsonValue = JSON.stringify(
          {
            'c': '10041',
            'p': {
              'tokenId': token(),
              'userId': JSON.parse(window.localStorage.data).id,
              'state': 2,
              "startIndex": 0, // 开始位置
              "pageSize": 10,   // 分页总数量
            }
          }
        )
        this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
          console.log(res)
          this.pindanList = res.data.p.mallInfoVoList
        })
      },
      isShow(n) {
        this.curId = n
      },
      removeItem(index) {
        if (this.curId === 0) {
          this.goodsList.splice(index, 1)
        } else {
          this.pindanList.splice(index, 1)
        }

      },
      removeAll() {
        if (this.curId === 0) {
          this.goodsList = []
        } else {
          this.pindanList = []
        }
      },
      goPinDan(index) {
        let goodsInfo = this.goodsList[index]
        console.log(goodsInfo)
        localStorage.setItem('pinDanGoodsInfo', JSON.stringify(goodsInfo));

        this.$router.push(
          {
            name: 'Collage',
            params: goodsInfo
          }
        )
      },
      // 上拉加载
      loadBottom: function () {
        this.startIndex += 1;
        this.fn10040(this.startIndex)
        this.$refs.loadmore.onBottomLoaded();// 固定方法，查询完要调用一次，用于重新定位
      }
    },
    computed: {
      number1() {
        return this.goodsList.length
      },
      number2() {
        return this.pindanList.length
      }
    },
    watch: {}
  }
</script>

<style scoped lang="scss">
  .content {
    width: 100%;
    background: #f4f4f4;
    margin-bottom: 90px;
    .top {
      background: #ffffff;
      height: 70px;
      width: 100%;
      text-align: center;
      display: flex;
      flex-flow: row nowrap;
      div {
        flex: 1;
        font-size: 24px;
        line-height: 70px;
        color: #3b3b43;
        width: 50%;
        &.select {
          color: #fe3519;
        }
        .num {
          display: inline-block;
          width: 32px;
          height: 32px;
          color: #ffffff;
          background: #bcbaba;
          text-align: center;
          line-height: 36px;
          border-radius: 50%;
          font-size: 20px;
          vertical-align: super;
          &.select {
            background: #fd6141;
          }
        }

      }

    }
    .kuncun {
      color: #8c8c8c;
      margin-left: 50px;
      font-size: 24px;
    }
    .con {
      .goodsList {
        .item {
          margin-top: 20px;
          background: #ffffff;
          .shops {
            height: 85px;
            border-bottom: 1px solid #f4f4f4;
            line-height: 85px;
            img {
              float: left;
              margin-left: 30px;
              margin-right: 28px;
              margin-top: 7px;
              width: 62px;
              height: 62px;
              border: 3px solid #f4f4f4;
              border-radius: 50%;
              background: #26a2ff;
            }
            span {
              font-size: 24px;
              color: #3b3b43;

            }
            div {
              float: right;
              font-size: 24px;
              color: #fe3519;
              margin-right: 40px;
            }
          }
          .goods {
            box-sizing: border-box;
            padding-left: 27px;
            height: 222px;
            display: flex;
            flex-flow: row nowrap;
            .img {
              margin-top: 22px;
              width: 174px;
              height: 174px;
              margin-right: 18px;
              background: lightskyblue;
              img {
                width: 100%;
                height: 100%;
              }
            }
            .text {
              flex: 1;
              p:nth-child(1) {
                margin-top: 20px;
                font-size: 24px;
                line-height: 50px;
                color: #3b3b43;
              }
              p:nth-child(2) {
                color: #fe3519;
                font-size: 32px;
                margin-top: 16px;
                margin-bottom: 12px;
              }
              p:nth-child(3) {
                font-size: 20px;
                color: #a1a1a1;
                span:nth-child(1) {
                  margin-right: 35px;
                }
              }
            }
          }
          .bottom {
            border-top: 1px solid #f4f4f4;
            display: flex;
            flex-flow: row nowrap;
            justify-content: flex-end;
            font-size: 24px;
            height: 92px;
            line-height: 92px;
            background: #FFFFFF;
            div {
              margin: 16px 30px 0px 15px;
              width: 180px;
              height: 64px;
              text-align: center;
              line-height: 64px;
              background: url("btn_2@1x.png");
              background-size: 100% 100%;
              color: #fe3519;
              &.gopin {
                background: url("btn_1@1x.png");
                background-size: 100% 100%;
                color: #ffffff;
              }
            }

          }
        }
      }
      .pinDanList {
        .item {
          margin-top: 20px;
          background: #ffffff;
          .shops {
            height: 85px;
            border-bottom: 1px solid #f4f4f4;
            line-height: 85px;
            img {
              float: left;
              margin-left: 30px;
              margin-right: 28px;
              margin-top: 7px;
              width: 62px;
              height: 62px;
              border: 3px solid #f4f4f4;
              border-radius: 50%;
              background: #26a2ff;
            }
            span {
              font-size: 24px;
              color: #3b3b43;

            }
            div {
              float: right;
              font-size: 24px;
              color: #fe3519;
              margin-right: 40px;
            }
          }
          .goods {
            box-sizing: border-box;
            padding-left: 27px;
            height: 222px;
            display: flex;
            flex-flow: row nowrap;
            .img {
              margin-top: 22px;
              width: 174px;
              height: 174px;
              margin-right: 18px;
              background: lightskyblue;
              img {
                width: 100%;
                height: 100%;
              }
            }
            .text {
              flex: 1;
              p:nth-child(1) {
                margin-top: 20px;
                font-size: 24px;
                line-height: 50px;
                color: #3b3b43;
              }
              p:nth-child(2) {
                color: #fe3519;
                font-size: 32px;
                margin-top: 26px;
                margin-bottom: 12px;
              }
              p:nth-child(3) {
                font-size: 20px;
                color: #a1a1a1;
                span:nth-child(1) {
                  margin-right: 35px;
                }
              }
            }
          }
          .bottom {
            border-top: 1px solid #f4f4f4;
            display: flex;
            flex-flow: row nowrap;
            justify-content: flex-end;
            font-size: 24px;
            height: 92px;
            line-height: 92px;
            background: #FFFFFF;
            div {
              margin: 16px 30px 0px 15px;
              width: 180px;
              height: 64px;
              text-align: center;
              line-height: 64px;
              background: url("btn_2@1x.png");
              background-size: 100% 100%;
              color: #fe3519;
              &.gopin {
                background: url("btn_1@1x.png");
                background-size: 100% 100%;
                color: #ffffff;
              }
            }

          }
        }
      }
    }
    footer {
      width: 100%;
      position: fixed;
      bottom: 0;
      display: flex;
      flex-flow: row nowrap;
      justify-content: space-around;
      height: 80px;
      text-align: center;
      line-height: 80px;
      font-size: 24px;
      font-weight: bold;
      background: #ffffff;
      div {
        outline: 1px solid #e5e5e5;
        flex: 1;
        width: 50%;
      }
      div:nth-child(2) {
        color: #fe3519;
      }
    }
  }
</style>
